
var ChargingStandard = {
	starting_price: [
		{
			hour: {
				s: 0, e: 6
			},
			price: 59,
		},
		{
			hour: {
				s: 22, e: 24
			},
			price: 59,
		},
		{
			hour: {
				s: 7, e: 21
			},
			price: 39,
		}
	],
	
	price_per_waiting_time: {
		length_of_time: 30,
		price: 20,
	},

	starting_km: 10,
	price_per_km: {
		length_of_km: 5,
		price: 20,
	}
};

/*
order : {
	arrive_time 到达时间
	start_time  开车时间
	driver_length 驾驶距离

}
 */

var duration = function (end, start) {
	var seconds = Number(moment(end).format('X')) - Number(moment(start).format('X'));

	return seconds;
};

var calcStartingPrice = function (hour) {
	var sps = ChargingStandard.starting_price;
	var price = 0;
	for (var i = 0; i < sps.length; i++) {
		if (hour >= sps[i].hour.s && hour <= sps[i].hour.e) {
			price = sps[i].price;
			return price;
		}
	};

	return price;
};

calcPrice = function (order) {
	var price = 0;

	if (order.driver_length <= 0)
		return price;

	var waiting_minute = duration(order.start_time, order.arrive_time) / 60;
	
	var waiting_price = parseInt(waiting_minute / ChargingStandard.price_per_waiting_time.length_of_time) * ChargingStandard.price_per_waiting_time.price;
	price += waiting_price;
	console.log(waiting_price);
	var starting_hour = moment(order.start_time).get('hour');
	var starting_price = calcStartingPrice( starting_hour );

	price += starting_price;
	console.log(starting_price);
	var driver_km = parseInt(order.driver_length / 1000);
	var driver_price;
	if (driver_km <= ChargingStandard.starting_km)
		driver_price = 0
	else
	 	driver_price = (driver_km - ChargingStandard.starting_km) / ChargingStandard.price_per_km.length_of_km * ChargingStandard.price_per_km.price;
	price += driver_price;
	console.log(driver_price);
	return price;
};